const express = require('express')
const cors = require('cors')
//const fileUpload = require('express-fileupload')
const https = require('https')
const http = require('http')
const fs = require('fs')
const app = express()
const addServices = require('./service')

app.use(cors())
//app.use(fileUpload({ createParentPath: true }))
app.use(express.json())
app.use('/img', express.static('img'))

addServices(app)

const hostname = '127.0.0.1'
const port = 3000

const options = {
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem')
}

http.createServer(app).listen(port)
https.createServer(options, app).listen(port + 1)

console.log(`Server is running at http://${hostname}:${port} and https://${hostname}:${port + 1}`)
